package com.blacksheep.mtm.service.Impl;

import com.blacksheep.mtm.common.exception.XmallException;
import com.blacksheep.mtm.dao.TbBounsMapper;
import com.blacksheep.mtm.dao.TbMemberMapper;
import com.blacksheep.mtm.pojo.manager.TbBouns;
import com.blacksheep.mtm.pojo.manager.TbMember;
import com.blacksheep.mtm.service.BounsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

@Service
public class BounsServiceImpl implements BounsService {



    @Autowired
    private TbMemberMapper memberMapper;
    @Autowired
    private TbBounsMapper bounsMapper;


    @Override
    public int getBounsListCount(String openid) {
        TbMember member = memberMapper.selectMemberByOpenid(openid);
        if (member == null) {
            throw new XmallException("会员不存在!请重新登录~");
        }
        if (member.getState() < 0) {
            throw new XmallException("会员被冻结!");
        }
        //这里只会取订单已经完成的数量
        int result = bounsMapper.selectCountByMemberId(member.getId(), 0);
        return result;
    }

    @Override
    public List<TbBouns> getBounsList(String openid) {
        TbMember member = memberMapper.selectMemberByOpenid(openid);
        if (member == null) {
            throw new XmallException("会员不存在!请重新登录~");
        }
        //这里只会取订单已经完成的数量
        List<TbBouns> list = bounsMapper.selectListByMemberId(member.getId(), 0);

        return list;
    }

    @Override
    public int getBounsPoints(String openid) {
        TbMember member = memberMapper.selectMemberByOpenid(openid);
        if (member == null) {
            throw new XmallException("会员不存在!请重新登录~");
        }
        return bounsMapper.selectSumPointsByMemberId(member.getId());
    }


}
